#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define MAXSIZE 100
typedef struct
{
	char ch[MAXSIZE];
	int Len;
}String;
int StrLength(String* S)
{
	int i = 0;
	while (S->ch[i] != '\0')
		i++;
	S->Len = i;
	return (S->Len);
}
void CreatStr(String* S)
{
	gets(S->ch);
	S->Len = StrLength(S);
}
int SubString(String* S, String* Sub, int pos, int len)
{
	int j;
	if (pos<1 || pos>S->Len || len<1 || len>S->Len-pos + 1)
	{
		Sub->Len = 0;
		printf("参数错误！\n");
		return 0;
	}
	else
	{
		for (j = 0; j < len; j++)
			Sub->ch[j] = S->ch[pos + j - 1];
		Sub->ch[j] = '\0';
		Sub->Len = len;
		return 1;
	}
}
int StrIndex(String* S, String* T)
{
	int i = 0, j = 0, k = 0;
	while (i < S->Len && j < T->Len)
	{
		if (S->ch[i] == T->ch[j])
		{
			i++;
			j++;
		}
		else
		{
			i = i - j + 1;
			j = 0;
		}
	}
	if (j >= T->Len)
		k = i - T->Len + 1;
	else
		k = -1;
	return k;
}
int main()
{
	int i, len, flag;
	String x, y, z;
	String* S = &x, * S1 = &y;
	char ch1, ch2, a;
	ch1 = 'y';
	while (ch1 == 'y' || ch1 == 'Y')
	{
		scanf("%c", &ch2);
		getchar();
		switch (ch2)
		{
		case '1':
			CreatStr(S);
			printf("该串值为:\n");
			if (S->ch[0] == '\0')
				printf("空串");
			else
			{
				puts(S->ch);
				printf("该串的长度为:%d", S -> Len);
			}
			scanf("%c", &ch1);
			CreatStr(S1);
			i = StrIndex(S, S1);
			if (i == -1)
				printf("失败");
			else
				printf("查找成功，该字串在主串中第一次出现的位置为%d", i);
			break;
		}
		break;
	}
	
}